<template>
  <avue-crud
    ref="smsRef"
    :table-loading="tableLoading"
    v-model="form_deposit"
    :option="option_deposit"
    @refresh-change="getList"
    @row-update="rowUpdate"
    :data="data"
  ></avue-crud>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { getSMSList, updateSMS } from "@/apis/admin";
import { ElMessage } from "element-plus";
const tableLoading = ref(false);
const data = ref([]);
const form_deposit = ref({});
const option_deposit = ref({
  index: true,
  border: true,
  stripe: true,
  menuAlign: "center",
  loadingText: "加载中...",
  loadingSpinner: "svg",
  loadingSvgViewBox: "-10, -10, 50, 50",
  loadingBackground: "rgba(122, 122, 122, 0.6)",
  searchShow: false,
  columnBtn: false,
  addBtn: false,
  delBtn: false,
  column: [
    {
      label: "name",
      prop: "name",
      disabled: true,
    },
    // {
    //   label: "apiUrl",
    //   prop: "apiUrl",
    // },
    // {
    //   label: "apiKey",
    //   prop: "apiKey",
    // },
    // {
    //   label: "apiCode",
    //   prop: "apiCode",
    // },
    // {
    //   label: "apiCode",
    //   prop: "apiCode",
    // },
    // {
    //   label: "appSecret",
    //   prop: "appSecret",
    // },
    // {
    //   label: "appSecret",
    //   prop: "appSecret",
    // },
    {
      label: "状态",
      prop: "status",
      type: "select",
      dicData: [
        {
          label: "未使用",
          value: 0,
        },
        {
          label: "使用中",
          value: 1,
        },
      ],
      formatter: (row, value, column) => {
        return row.status ? "使用中" : "未使用";
      },
    },
    {
      label: "更新时间",
      prop: "updateTime",
      display: false,
      formatter: (row, value, column) => {
        return formatDate(row.updateTime * 1000, "-");
      },
    },
  ],
});
const formatDate = (date, cut) => {
  var date = new Date(date);
  var YY = date.getFullYear() + cut;
  var MM =
    (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + cut;
  var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  var hh = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  var mm = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + ":";
  var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  return YY + MM + DD + " " + hh + mm + ss;
};
const rowUpdate = async (row, index, done, loading) => {
  const res = await updateSMS.post("", {
    name: row.name,
    status: row.status,
  });
  if (res.code == 200) {
    ElMessage.success("编辑成功");
    getList();
  }
  done();
};
const getList = () => {
  tableLoading.value = true;
  getSMSList.get("", {}).then((res) => {
    tableLoading.value = false;
    if (res.code == 200) {
      data.value = res.data.list;
    }
  });
};
onMounted(() => {
  getList();
});
</script>
